import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex);

export default new Vuex.Store({
    plugins: [createPersistedState({
        key: 'rz-admin'
    })],
    state: {
        isCollapse: true,
        activeTab: "",
        admin: {
            id: ""
        },
        resList: [],
        resTreeList: [],
        tabs: []
    },
    mutations: {
        clearLoginInfo(state) {
            state.admin = {
                id: ""
            }
            state.resList = []
            state.resTreeList = []
            state.tabs = [];
            state.activeTab = "";
        },
        setLoginInfo(state, data) {
            state.admin = data.admin
            state.resList = data.resList
            state.resTreeList = data.resTreeList[0].children
        },
        syncRes(state, data) {
            state.resList = data.resList
            // state.resTreeList = data.resTreeList[0].children
        },
        setActiveTab(state, key) {
            state.activeTab = key;
        },
        setTabs(state, tabs) {
            state.tabs = tabs;
        },
        setCollapse(state, isCollapse) {
            state.isCollapse = isCollapse
        }
    },
    actions: {}
});